"use strict";

const gulp = require("gulp");
const babel = require("gulp-babel");
// const stripDebug = require("gulp-strip-debug");
const clean = require("gulp-clean");
// const outputDir = "./" + "frontFile";

const outputDir = "./" + "front";
function js() {
  console.log("start js");
  return (
    gulp
      // .src( '*/js/index.js')
      .src(["./src/front/**/index.js", "!./src/front/**/*.min.js"])
      // .pipe(stripDebug()) // 去除所有console语句
      .pipe(
        babel({
          presets: ["@babel/env"],
        })
      )
      .pipe(gulp.dest(outputDir))
  );
}
function minjs() {
  console.log("start minjs");
  return gulp
    .src(["./src/front/**/*.min.js", "./src/front/*js*/*.js"])
    .pipe(gulp.dest(outputDir));
}
function css() {
  console.log("start css");
  return (
    gulp
      .src(["./src/front/**/*.+(scss|css)"])
      // .pipe(autoprefixer())
      // .pipe(sass().on("error", sass.logError))
      .pipe(gulp.dest(outputDir))
  );
}

function html() {
  console.log("start html");
  return gulp.src("./src/front/**/*.html").pipe(gulp.dest(outputDir));
}

function remove() {
  console.log("clean start");
  return gulp
    .src("./" + outputDir, { read: false, allowEmpty: true })
    .pipe(clean());
}

// 默认打包
gulp.task("default", gulp.series(remove, gulp.parallel(js, minjs, css, html)));
